//
//  MXNewViewTitleMenuVC.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/19.
//  Copyright (c) 2015年 霄 马. All rights reserved.
//
#define WIDTH ([UIScreen mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height)
#import "MXNewViewTitleMenuVC.h"
#import "AFNetworkHandler.h"
#import "MXNewViewTitleMenuModel.h"
#import "MXNewViewVC.h"
@interface MXNewViewTitleMenuVC ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) NSMutableArray *itemArray;
@end

@implementation MXNewViewTitleMenuVC
- (void)dealloc
{
    [_itemArray release];
    [_tableView reloadData];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    
    self.itemArray = [NSMutableArray array];
    
    [self getData];
    
    [self creatTableView];
    // Do any additional setup after loading the view.
}
- (void)creatTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTHPRO * 200, HEIGHTPRO * 300) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.tableView];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return self.itemArray.count;
}






- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"cell"];
    }
    
    [cell.textLabel setTextColor:[UIColor whiteColor]];
    
    cell.backgroundColor = [UIColor clearColor];
    
    cell.textLabel.text  = [self.itemArray[indexPath.row] app_name];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate getShopTag:[self.itemArray[indexPath.row] app_name] select:YES];
//    NSLog(@"%@", [self.itemArray[indexPath.row] app_name]);
    
    
}

- (void)getData
{
    NSString *Path = @"http://rm.app.hongniujia.com/json_shop.php?action=category&appCookie=channel_AppStore%20version_6.11%20oid_AE53CF37-EAEB-468C-8507-15A922FDD348%20package_com.aslibra.rm.nanren%20platform_iphone%20ver_8.4.1%20jb_0%20t1_1439954228%20md5_88%20t_1438671553";
    [AFNetworkHandler GETwithAFNByURL:Path completion:^(id result) {
        NSArray *dataArr = result;
        for (NSDictionary *dict in dataArr) {
            MXNewViewTitleMenuModel *model = [[[MXNewViewTitleMenuModel alloc] initWithDic:dict] autorelease];
            [self.itemArray addObject:model];
        }
        
        [self.tableView reloadData];
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
